package com.canyou.activiti;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.canyou.activiti.entity.ActHighLineVO;
import com.canyou.activiti.entity.ActHistoryVO;
import com.canyou.activiti.entity.FormDataVO;
import com.canyou.activiti.service.ActHistoryService;
import com.canyou.api.BaseApiController;
import com.canyou.api.ResponseBO;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

import static com.canyou.api.ResponseBO.*;

/**
 * 用户历史任务
 *
 * @author fy
 * @date 2021/3/3 14:49
 */
@RestController
@ApiSort(2004)
@Api(tags = "历史任务")
@RequestMapping("/act-history")
@Validated
public class ActHistoryController extends BaseApiController {

    @Autowired
    private ActHistoryService actHistoryService;

    @ApiOperation(value = "分页获取用户历史任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", paramType = "query", value = "当前第几页",
                    dataType = "int", required = false, example = PAGE_INDEX),
            @ApiImplicitParam(name = "pageSize", paramType = "query", value = "每页记录数",
                    dataType = "int", required = false, example = PAGE_SIZE)
    })
    @GetMapping("/get_page")
    public ResponseBO<IPage<ActHistoryVO>> getPageList(
            @RequestParam(defaultValue = PAGE_INDEX, required = false) int pageNumber,
            @RequestParam(defaultValue = PAGE_SIZE, required = false) int pageSize) {
        IPage<ActHistoryVO> page = new Page<>(pageNumber, pageSize);
        IPage<ActHistoryVO> pageList = actHistoryService.getPageList(page);
        return ok(pageList);
    }

    @ApiOperation(value = "流程图高亮")
    @ApiImplicitParam(name = "instanceId", paramType = "query", value = "流程实例id",
            dataType = "string", required = true, example = "23a5bc4f-7bc5-11eb-acd5-00ff042432dd")
    @GetMapping("/get_high_line")
    public ResponseBO<ActHighLineVO> getHighLine(@NotNull(message = "流程实例id不能为空") @RequestParam String instanceId) {
        return ok(actHistoryService.getHighLine(instanceId), "获取成功");
    }

    @ApiOperation(value = "获取已完成任务表单数据")
    @ApiImplicitParam(name = "instanceId", paramType = "query", value = "流程实例id",
            dataType = "string", required = true, example = "23a5bc4f-7bc5-11eb-acd5-00ff042432dd")
    @GetMapping("/get_history_form_data")
    public ResponseBO<List<FormDataVO>> getHistoryFormData(@NotNull(message = "流程实例id不能为空")
                                                           @RequestParam String instanceId) {
        return ok(actHistoryService.getHistoryFormData(instanceId), "获取成功");
    }

}
